Skip to content

fix(tholos): verify balance deltas for incoming token transfers (#164) - #181

Closed
xtep103 wants to merge 1 commit into
drydocs:mainfrom
xtep103:feat/exact-transfer-verification
Closed

fix(tholos): verify balance deltas for incoming token transfers (#164)#181
xtep103 wants to merge 1 commit into
drydocs:mainfrom
xtep103:feat/exact-transfer-verification

Conversation

@xtep103

@xtep103 xtep103 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Overview

Verifies balance deltas for incoming token transfers during assertion creation (assert_outcome) and disputes (dispute) in contracts/tholos, recording actual received tokens and protecting resolve and finalize payouts against deadlocks caused by fee-on-transfer tokens.

Related Issue

Closes #164

Changes

contracts/tholos

  • [MODIFY] contracts/tholos/src/lib.rs
    • Added balance delta checks around incoming token transfers in assert_outcome and dispute.
    • If actual received tokens are less than requested, records the received amount into assertion.bond in persistent storage. Rejects zero/negative received amounts with Error::InvalidBondAmount.
    • Clamped payouts in finalize (assertion.bond.min(contract_balance)) and resolve ((assertion.bond.saturating_mul(2)).min(contract_balance)) to prevent transfer failure panics when contract balances are constrained by transfer deductions.
  • [MODIFY] contracts/tholos/src/test.rs
    • Added FeeToken test fixture simulating configurable fee-on-transfer mechanics.
    • Added unit test test_fee_on_transfer_token_dispute_resolves_without_deadlock confirming assertions with fee tokens can be disputed and resolved without balance underflow.
    • Added unit test test_fee_on_transfer_token_finalize_resolves_without_deadlock confirming undisputed assertions with fee tokens finalize successfully.
    • Added unit test test_zero_received_transfer_rejected ensuring 100% fee transfers that deliver 0 tokens are rejected.

Verification Results

running 79 tests
test test::fee_token::test::test_fee_token_transfer ... ok
test test::test_fee_on_transfer_token_dispute_resolves_without_deadlock ... ok
test test::test_fee_on_transfer_token_finalize_resolves_without_deadlock ... ok
test test::test_zero_received_transfer_rejected ... ok
...
test result: ok. 79 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

cargo test --workspace --locked: 189 tests passed (79 tholos, 110 tholos-v2), 0 failed
cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
cargo fmt --check: OK
Acceptance Criteria Status
Balance deltas verified around token transfer calls in assert_outcome & dispute ✅ Implemented and verified
Actually received amount recorded in storage if short; 0-amount rejected ✅ Tested with Error::InvalidBondAmount
resolve / finalize clamped to available balance to prevent deadlock ✅ Tested and verified
Unit tests covering fee-on-transfer resolution & zero-transfer rejection ✅ All tests passing

@xtep103

xtep103 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing duplicate PR in favor of #180, which has been updated with the clean, verified commit history and full test suite.

@xtep103 xtep103 closed this Sep 4, 2026
@xtep103 xtep103 reopened this Sep 4, 2026
@collinsezedike

Copy link
Copy Markdown
Collaborator

@xtep103 closing this as a duplicate of #180, same diff, opened 20 minutes apart. Review findings are on #180, let's continue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] No exact-amount transfer verification permanently deadlocks a disputed assertion

2 participants